<extend name="Public/base"/>
<block name="head">
    <link rel="stylesheet" href="__PUBLIC__/dist/css/bootstrapValidator.css"/>
    <!--<link href="__PUBLIC__/dist/css/default.css" rel="stylesheet" type="text/css" />-->
    
</block>
<block name="body">
    <section class="content">

        <h4 class="modal-title" id="editModalLabel">
            编辑用户信息
        </h4>

        <form role="form" action="__URL__/update" method="post" id="UserForm" onsubmit="
                if(!hasMainEmailBox()){alert('至少需要一个主邮箱！');return false;}">
            <div class="box-body">

                <div class="form-group">
                    <label>用户名：</label>
                    <input type="text" class="form-control"   name="account" value="{$vo.account}">
                    <input type="hidden" class="form-control"  name="id" value="{$vo['id']}">
                </div>

                <div class="form-group">
                    <label>昵称：</label>
                    <input type="text" class="form-control" name="nickname" value="{$vo.nickname}">
                </div>
                <!--<div class="form-group">-->
                    <!--<label>Email：</label>-->
                    <!--<input type="text" name="email" size="30" maxlength="100" class="form-control required email" value="{$vo.email}">-->
                <!--</div>-->
                <div class="form-group">
                    <label>{$Think.lang.Email}</label>
                    <div class="col-sm-12 email-form-group">
                        <volist name="emaillist" id="v">
                            <?php $emailsufix = explode('@',$v['email']); ?>
                            <div class="email-item">
                                <div class="input-group col-md-10 pull-left input-group-1">
                                    <input type="text" class="form-control" name="email[]" value="{$emailsufix[0]}"  aria-label="...">
                                </div>
                                <div class="input-group-btn input-group-btn1" style="width: 130px !important;">
                                        <select name="mailbox_suffix[]" class="form-control mail-select  mail-sufix" >
                                            {$emailSuffix | renderOptions = $v['type_id'] == ''?'':$v['type_id']}
                                        </select>
                                </div>
                                <div class="input-group col-md-2 col-sm-2 pull-left">
                                    <div class="input-group-btn input-group-btn2">
                                        <select name="is_main[]" class="form-control mail-select mail-default" style="width: 100px !important;">
                                            <option value="0" <?php if($v['is_main']==0): ?>selected<?php endif; ?>>次邮箱</option>
                                            <option value="1" <?php if($v['is_main']): ?>selected<?php endif; ?>>主邮箱</option>
                                        </select>
                                    </div>
                                    <a href="javascript:;"  class="btn button btn-default email-ajaxremove email-ajaxremove-btn" data="{$v['id']}"><i class="fa fa-remove"></i></a>
                                </div>
                            </div>
                        </volist>
                    </div>
                    <div class="col-md-12 text-right "><a href="javascript:;"  class="btn button btn-primary  email-add">{$Think.lang.Add}</a> </div>
                </div>

                <div class="form-group">
                    <label>状态：</label>
                    <select class="small bLeft form-control"  name="status">
                        <option <eq name="vo.status" value="1" >selected</eq> value="1">启用</option>
                        <option <eq name="vo.status" value="0" >selected</eq> value="0">禁用</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="password">Password：</label>
                    <a href="__APP__/Public/viaEmail?uid={$vo.id}&admin=1" >
                        <button class="btn btn-block btn-primary" type="button">Retrieve password via email</button>
                    </a>
                </div>
                <div class="form-group">
                    <label>备  注：</label>
                    <textarea class="form-control"  name="remark" rows="5" cols="57">{$vo.remark}</textarea>
                </div>

                <div class="form-group">
                    <div class="col-lg-9 col-lg-offset-3">
                        <div id="errors"></div>
                    </div>
                </div>
            </div><!-- /.box-body -->

            <div class="box-footer">
                <button type="submit" class="btn btn-primary">Submit</button>
            </div>
        </form>


    </section>
</block>

<block name="script">
    <script src="__PUBLIC__/dist/js/bootstrapValidator.js" type="text/javascript"></script>
    <script src="__PUBLIC__/dist/js/language/zh_CN.js" type="text/javascript"></script>
    <script src="__PUBLIC__/dist/js/validator.js" type="text/javascript"></script>
    <script src="__PUBLIC__/dist/js/custom_email.js"></script>
    <script type="text/javascript">
        $(function () {
            Validator('UserForm');
            iniAjaxFormDetail('#UserForm','__URL__/Index/pid/1/');

            $('.email-add').bind('click',function(){
                var html = '<?php echo getAddEmailTemplate(); ?>';
                $(this).parent().prev().append(html);
                $('#UserForm').data('bootstrapValidator').destroy();
                Validator('UserForm','#errors');
            });

            $('.email-ajaxremove').on('click', function () {
                if (confirm('确认删除邮箱？')) {
                    if ( checkLastItem()){
                        if ($(this).prev().find('select').val() == 1){
                            alert('主邮箱不能删除！');
                            return;
                        }
                        var id = $(this).attr('data');
                        var then = $(this);
                        $.post('__APP__/Public/removeMailListItem',{
                            id : id
                        }).done(function(data){
                            if (data.status){
                                then.parents('.email-item').remove();
                                alert('删除成功！');
                            }else {
                                alert(data.info);
                            }
                        });
                    }else {
                        alert('至少存在一个邮箱！');
                    }
                }
            });
        });
            
            $(".email-form-group").on("click",".email-ajaxremove-btnon",function(){
                $(this).parent().parent().remove();
            })

    </script>
</block>
